package meta.api.web.value.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ValueMngDao {

    @Autowired
    private SqlSessionTemplate sqlSession;

    private static final String NAMESPACE = "meta.api.web.value.dao.valMng.";

    public int getTotal(String type, List<String> keys) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("type", type);
        params.put("keys", keys);
        return sqlSession.selectOne(NAMESPACE + "getTotal", params);
    }

    public List<String> getList(String type, List<String> keys,
            Integer current, Integer pageSize) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("type", type);
        params.put("keys", keys);
        if (current != null && pageSize != null) {
            params.put("current", pageSize * (current - 1));
            params.put("pageSize", pageSize);
        } else {
            params.put("current", null);
            params.put("pageSize", null);
        }
        return sqlSession.selectList(NAMESPACE + "getList", params);
    }

    public String getValue(String type, String key) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("type", type);
        params.put("key", key);
        return sqlSession.selectOne(NAMESPACE + "getValue", params);
    }
}
